
$(function(){
	// 绑定ICheck样式
	//WASP_WIDGET.triggerICheck();
	// 绑定IRadio样式
	//WASP_WIDGET.triggerIRadio();

//	WASP_WIDGET.triggerIRadio("input[type='radio'][name='timeQ']");
//	WASP_WIDGET.triggerIRadio("input[type='radio'][name='timeQ']",function(){
//		initProductFyDetail();
//	},function(){
//		//initProductFyDetail();
//	});
	
//	$('[type=checkbox]').iCheck({
//		checkboxClass : 'icheckbox_square-green',
//	});
	
	initProductFyDetail('1');
	initProductFyDetail2('1');
	bindRadioboxDivClick();
});

//投资者报告单选按钮事件
function bindRadioboxDivClick(){
	$("div[id='radioboxDiv']").find("span.subSelector").each(function(index){
		$(this).on('click',function(){
			$('#radioboxDiv .font-color-white').each(function(index,element){
				$(element).removeClass('font-color-white');
			});
			$(this).toggleClass("font-color-white");
			var reportFrequency = $(this).attr("reportFrequency");
			//initProductFyDetail(reportFrequency);
			initProductFyDetail(reportFrequency);
			initProductFyDetail2(reportFrequency);
		});
	});
}

function initProductFyDetail(cTimeQ){
	//var timeQ=$('#radioboxDiv').find('input[name=timeQ]:checked').val();
	var timeQ=cTimeQ;
	
	/**预计*/
	var tgfAmountYJ = 0;
	var glfAmountYJ = 0;
	var bjAmountYJ = 0;
	var fhAmountYJ = 0;
	/** 实际*/
	var tgfAmountSJ = 0;
	var glfAmountSJ = 0;
	var bjAmountSJ = 0;
	var fhAmountSJ = 0;
	
	$.ajax({
		url : fyPath+"getYJandSJAmount.do",
		data : {
			'type':timeQ
		},
		dataType : "json",
		cache : false,
		async: false,
		error : function(textStatus, errorThrown) {
			ctools.alert("系统ajax交互错误: ",'',"warning");
		},
		success : function(data) {
			if(data != null){
				tgfAmountYJ = parseFloat(data.tgfAmountYJ);
				glfAmountYJ = parseFloat(data.glfAmountYJ);
				bjAmountYJ = parseFloat(data.bjAmountYJ);
				fhAmountYJ = parseFloat(data.fhAmountYJ);
				tgfAmountSJ = parseFloat(data.tgfAmountSJ);
				glfAmountSJ = parseFloat(data.glfAmountSJ);
				bjAmountSJ = parseFloat(data.bjAmountSJ);
				fhAmountSJ = parseFloat(data.fhAmountSJ);
			}
		}
	});
	
	//条形图表 预计
	var barChart = echarts.init(document.getElementById('barChart1')); 
	barChart.clear();  
	barChart.showLoading({text: '正在努力的读取数据中...'}); 
	var option1 = {
			title: {
		        text: '应付金额',
		        left:'center'
		    },
		    xAxis: {
		        type: 'category',
		        axisTick:{
		        	//是否显示坐标轴刻度
		        	show:false,
		        	alignWithLabel:false
		        },
		        /*axisLine:{
		        	// 轴末端是否显示(箭头)图标
		        	symbol:['none', 'arrow']
		        },*/
		        data: [ '托管费', '管理费', '本金','分红']
		    },
		    yAxis: {
		    	name: '金额(万元)',
		        type: 'value',
		        //是否显示分隔线
		        splitLine:{
		        	show:false
		        },
		        axisTick:{
		        	//是否显示坐标轴刻度
		        	show:false,
		        	alignWithLabel:false
		        },
		        //是否显示刻度标签
		        axisLabel: {
		        	show: false
		        },
		       /*,
		        axisLine:{
		        	// 轴末端是否显示(箭头)图标
		        	symbol:['none', 'arrow']
		        }*/
		    },
		    series: [{
		    	label:{
		    		normal:{
		    			show:true,
		    			position:'top'
		    		}
		    	},
		        data: [ {value:tgfAmountYJ, name: '托管费'},
		        	    {value:glfAmountYJ, name: '管理费'},
			        	{value:bjAmountYJ, name: '本金'},
			        	{value:fhAmountYJ, name: '分红'}],
		        type: 'bar',
		        //color: ['#FF7F50', '#66CDAA ', '#FF69B4','#DAA520'],
		        // 设置柱体的颜色
		        itemStyle:{
		        	normal:{
		        		color:function(params){
		        			var colorList = ['#FF7F50', '#66CDAA ', '#FF69B4','#DAA520'];
		        			return colorList[params.dataIndex]
		        		}
		        	}
		        }
		    }]
		};
	
	//条形图表 实际
	var barChart2 = echarts.init(document.getElementById('barChart2')); 
	barChart2.clear();  
	barChart2.showLoading({text: '正在努力的读取数据中...'}); 
	var option2 = {
			title: {
		        text: '实付金额',
		        left:'center'
		    },
		    xAxis: {
		        type: 'category',
		        axisTick:{
		        	//是否显示坐标轴刻度
		        	show:false,
		        	alignWithLabel:false
		        },
		        /*axisLine:{
		        	// 轴末端是否显示(箭头)图标
		        	symbol:['none', 'arrow']
		        },*/
		        data: [ '托管费', '管理费', '本金','分红']
		    },
		    yAxis: {
		    	name: '金额(万元)',
		        type: 'value',
		        //是否显示分隔线
		        splitLine:{
		        	show:false
		        },
		        axisTick:{
		        	//是否显示坐标轴刻度
		        	show:false,
		        	alignWithLabel:false
		        },
		        //是否显示刻度标签
		        axisLabel: {
		        	show: false
		        },
		       /*,
		        axisLine:{
		        	// 轴末端是否显示(箭头)图标
		        	symbol:['none', 'arrow']
		        }*/
		    },
		    series: [{
		    	label:{
		    		normal:{
		    			show:true,
		    			position:'top'
		    		}
		    	},
		    	data: [ {value:tgfAmountSJ, name: '托管费'},
	        	        {value:glfAmountSJ, name: '管理费'},
		        	    {value:bjAmountSJ, name: '本金'},
		        	    {value:fhAmountSJ, name: '分红'}],
		        type: 'bar',
		        //color: ['#FF7F50', '#66CDAA ', '#FF69B4','#DAA520'],
		        // 设置柱体的颜色
		        itemStyle:{
		        	normal:{
		        		color:function(params){
		        			var colorList = ['#FF7F50', '#66CDAA ', '#FF69B4','#DAA520'];
		        			return colorList[params.dataIndex]
		        		}
		        	}
		        }
		    }]
		};
	
	//载入图表  
	loadDrugs(barChart,option1);
	loadDrugs(barChart2,option2);
	
	barChart.on("click", fyView1);
	barChart2.on("click", fyView2);
}

function fyView1(param) {
	var timeQ=$("div[id='radioboxDiv']").find(".font-color-white").attr("reportFrequency");
	var feeType = "";
	if(param.name == "管理费"){
		feeType = "FM01";
	}
	if(param.name == "托管费"){
		feeType = "FC01";
	}
	if(param.name == "分红"){
		feeType = "PY99";
	}
	if(param.name == "本金"){
		feeType = "PZ99";
	}
	
	var url = "/solution/business/customerEquity/prdFeeYield/prdFeeYieldListForCustomerEquity.do?feeType="+feeType+"&dateType=1"+"&type="+timeQ;
	window.location.href= url;
}

function fyView2(param) {
	var timeQ=$("div[id='radioboxDiv']").find(".font-color-white").attr("reportFrequency");
	var feeType = "";
	if(param.name == "管理费"){
		feeType = "FM01";
	}
	if(param.name == "托管费"){
		feeType = "FC01";
	}
	if(param.name == "分红"){
		feeType = "PY99";
	}
	if(param.name == "本金"){
		feeType = "PZ99";
	}
	
	var url = "/solution/business/customerEquity/prdFeeYield/prdFeeYieldListForCustomerEquity.do?feeType="+feeType+"&dateType=2"+"&type="+timeQ;
	window.location.href= url;
}

//查询  
//function loadDrugs(element,option) {  
//	
//	element.setOption(option, true);  
//	element.hideLoading();
//} 

function initProductFyDetail2(cTimeQ){
	//var timeQ=$('#radioboxDiv').find('input[name=timeQ]:checked').val();
	var timeQ=cTimeQ;
	
	/**预计*/
	var tgfAmountYJ = 0;
	var glfAmountYJ = 0;
	var bjAmountYJ = 0;
	var fhAmountYJ = 0;
	/** 实际*/
	var tgfAmountSJ = 0;
	var glfAmountSJ = 0;
	var bjAmountSJ = 0;
	var fhAmountSJ = 0;
	
	$.ajax({
		url : fyPath+"getYJandSJCount.do",
		data : {
			'type':timeQ
		},
		dataType : "json",
		cache : false,
		async: false,
		error : function(textStatus, errorThrown) {
			ctools.alert("系统ajax交互错误: ",'',"warning");
		},
		success : function(data) {
			if(data != null){
				tgfAmountYJ = parseFloat(data.tgfAmountYJ);
				glfAmountYJ = parseFloat(data.glfAmountYJ);
				bjAmountYJ = parseFloat(data.bjAmountYJ);
				fhAmountYJ = parseFloat(data.fhAmountYJ);
				tgfAmountSJ = parseFloat(data.tgfAmountSJ);
				glfAmountSJ = parseFloat(data.glfAmountSJ);
				bjAmountSJ = parseFloat(data.bjAmountSJ);
				fhAmountSJ = parseFloat(data.fhAmountSJ);
			}
		}
	});
	
	//条形图表 预计
	var barChart3 = echarts.init(document.getElementById('barChart3')); 
	barChart3.clear();  
	barChart3.showLoading({text: '正在努力的读取数据中...'}); 
	var option3 = {
			title: {
		        text: '应付产品数量',
		        left:'center'
		    },
		    xAxis: {
		        type: 'category',
		        axisTick:{
		        	//是否显示坐标轴刻度
		        	show:false,
		        	alignWithLabel:false
		        },
		        /*axisLine:{
		        	// 轴末端是否显示(箭头)图标
		        	symbol:['none', 'arrow']
		        },*/
		        data: [ '托管费', '管理费', '本金','分红']
		    },
		    yAxis: {
		    	name: '产品个数',
		        type: 'value',
		        //是否显示分隔线
		        splitLine:{
		        	show:false
		        },
		        axisTick:{
		        	//是否显示坐标轴刻度
		        	show:false,
		        	alignWithLabel:false
		        },
		        //是否显示刻度标签
		        axisLabel: {
		        	show: false
		        },
		       /*,
		        axisLine:{
		        	// 轴末端是否显示(箭头)图标
		        	symbol:['none', 'arrow']
		        }*/
		    },
		    series: [{
		    	label:{
		    		normal:{
		    			show:true,
		    			position:'top'
		    		}
		    	},
		        data: [ {value:tgfAmountYJ, name: '托管费'},
	        	        {value:glfAmountYJ, name: '管理费'},
			        	{value:bjAmountYJ, name: '本金'},
			        	{value:fhAmountYJ, name: '分红'}],
		        type: 'bar',
		        //color: ['#FF7F50', '#66CDAA ', '#FF69B4','#DAA520'],
		        // 设置柱体的颜色
		        itemStyle:{
		        	normal:{
		        		color:function(params){
		        			var colorList = ['#FF7F50', '#66CDAA ', '#FF69B4','#DAA520'];
		        			return colorList[params.dataIndex]
		        		}
		        	}
		        }
		    }]
		};
	
	//条形图表 实际
	var barChart4 = echarts.init(document.getElementById('barChart4')); 
	barChart4.clear();  
	barChart4.showLoading({text: '正在努力的读取数据中...'}); 
	var option4 = {
			title: {
		        text: '实付产品数量',
		        left:'center'
		    },
		    xAxis: {
		        type: 'category',
		        axisTick:{
		        	//是否显示坐标轴刻度
		        	show:false,
		        	alignWithLabel:false
		        },
		        /*axisLine:{
		        	// 轴末端是否显示(箭头)图标
		        	symbol:['none', 'arrow']
		        },*/
		        data: [ '托管费', '管理费', '本金','分红']
		    },
		    yAxis: {
		    	name: '产品个数',
		        type: 'value',
		        //是否显示分隔线
		        splitLine:{
		        	show:false
		        },
		        axisTick:{
		        	//是否显示坐标轴刻度
		        	show:false,
		        	alignWithLabel:false
		        },
		        //是否显示刻度标签
		        axisLabel: {
		        	show: false
		        },
		       /*,
		        axisLine:{
		        	// 轴末端是否显示(箭头)图标
		        	symbol:['none', 'arrow']
		        }*/
		    },
		    series: [{
		    	label:{
		    		normal:{
		    			show:true,
		    			position:'top'
		    		}
		    	},
		    	data: [ {value:tgfAmountSJ, name: '托管费'},
	        	        {value:glfAmountSJ, name: '管理费'},
		        	    {value:bjAmountSJ, name: '本金'},
		        	    {value:fhAmountSJ, name: '分红'}],
		        type: 'bar',
		        //color: ['#FF7F50', '#66CDAA ', '#FF69B4','#DAA520'],
		        // 设置柱体的颜色
		        itemStyle:{
		        	normal:{
		        		color:function(params){
		        			var colorList = ['#FF7F50', '#66CDAA ', '#FF69B4','#DAA520'];
		        			return colorList[params.dataIndex]
		        		}
		        	}
		        }
		    }]
		};
	
	//载入图表  
	loadDrugs(barChart3,option3);
	loadDrugs(barChart4,option4);
	
	barChart3.on("click", fyView1);
	barChart4.on("click", fyView2);
}

//导出
function exportToExcel(){
	var prjsName = "";
	var outCode = "";
	var subFundsName = "";
    var fundCode = "";
    var feeName = "";
    var expectPayDateBegin = "";
    var expectPayDateEnd = "";
    var bnsDateBegin = "";
    var bnsDateEnd = "";
    var isPay = "";
    var feeType = "";
    var deptId = "";
	var mgrId = "";
    
	var timeQ=$("div[id='radioboxDiv']").find(".font-color-white").attr("reportFrequency");
	
	var url = "/solution/business/customerEquity/prdFeeYield/exportToExcel.do?type="+timeQ;
	
    var urlParam ='&sp[prjsName]='+prjsName
	+'&sp[outCode]='+outCode
	+'&sp[subFundsName]='+subFundsName
	+'&sp[fundCode]='+fundCode
	+'&sp[feeName]='+feeName
	+'&sp[expectPayDateBegin]='+expectPayDateBegin
	+'&sp[expectPayDateEnd]='+expectPayDateEnd
	+'&sp[bnsDateBegin]='+bnsDateBegin
	+'&sp[bnsDateEnd]='+bnsDateEnd
	+'&sp[feeType]='+feeType
	+'&sp[isPay]='+isPay
	+'&sp[deptId]='+deptId
	+'&sp[mgrId]='+mgrId;
	
	var actionUrl = url+urlParam;
	openDialog(actionUrl);
}